package com.lanqiao.gxnushop.mapper;

import com.lanqiao.gxnushop.entity.Promotions;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Schema(description ="促销活动表")
@Mapper
public interface PromotionsMapper {
    @Schema(description ="添加促销活动")
    @Insert("insert into promotions(promotionId,storeId,name,discountType,discountValue,startDate,endDate,state) values (#{promotionId},#{storeId},#{name},#{discountType},#{discountValue},#{startDate},#{endDate},#{state})")
    boolean add(Promotions promotions);

    @Schema(description ="删除促销活动")
    @Delete("delete from promotions where promotionId=#{promotionId}")
    boolean delete(String promotionId);

    @Schema(description ="根据促销活动id查询促销活动")
    @Select("select * from promotions where promotionId=#{promotionId}")
    Promotions findById(String promotionId);

    @Schema(description ="更新促销活动")
    @Update("update promotions set name=#{name},discountType=#{discountType},discountValue=#{discountValue},startDate=#{startDate},endDate=#{endDate},state=#{state} where promotionId=#{promotionId}")
    boolean update(Promotions promotions);

    @Schema(description ="根据店铺id查询促销活动")
    @Select("select * from promotions where storeId=#{storeId}")
    ArrayList<Promotions> findByStoreId(String storeId);

    @Schema(description ="根据促销活动名称模糊查询促销活动")
    @Select("select * from promotions where name like concat('%',#{name},'%')")
    ArrayList<Promotions> findByName(String name);

    @Schema(description ="查询所有促销活动")
    @Select("select * from promotions")
    ArrayList<Promotions> selectAll();
}
